<div class="content-box"><!-- Start Content Box -->
   
    <div class="content-box-header">
        
        <h3>Video</h3>
        
        <ul class="content-box-tabs">
       
            <li><a href="#tab1" class="default-tab">Table</a></li> <!-- href must be unique and match the id of target div -->
            <li><a href="#tab2">Forms</a></li>
        </ul>
        
        <div class="clear"></div>
        
    </div> <!-- End .content-box-header -->
    
    <div class="content-box-content">
   
        <div class="tab-content default-tab" id="tab1">
<div class="qt-child-container">
<div class="qt-container-composer1">
<?php
	$txt_tieude='';$txt_anh='';$txt_mota='';$txt_noidung='';$txt_trangthai='';
	$hide_show=1;$id='';
	if(isset($_GET['id']))
		$id =$_GET['id'];
	
	if(isset($_POST['txt_tieude']))		{$txt_tieude=$_POST['txt_tieude'];$hide_show=0;}
	if(isset($_POST['txt_anh']))		$txt_anh=$_POST['txt_anh'];
	if(isset($_POST['txt_mota']))		$txt_mota=$_POST['txt_mota'];
	if(isset($_POST['txt_noidung']))	$txt_noidung=$_POST['txt_noidung'];
	if(isset($_POST['txt_trangthai']))	$txt_trangthai=$_POST['txt_trangthai'];
	
	if($hide_show==1)
	{
		$sql3='	SELECT 				*
							FROM 	tbl_tintuc
							WHERE tbl_tintuc.id='.$id.'';
		$result3=mysql_query($sql3);
				// Lay du lieu day vao form
		$num=mysql_num_rows($result3);
		if($num==1)
		{
			while($row=mysql_fetch_array($result3))
			{
				
				$txt_tieude=$row['tieude'];
				$txt_anh=$row['anh'];
				$txt_mota=$row['mota'];
				$txt_noidung=$row['noidung'];
				$txt_trangthai=$row['trangthai'];
			}
		}
	?>
   <!-- <h1>Edit: </h1>-->
<form action="" method="post" enctype="multipart/form-data">
   <fieldset>
   	<p>
		<label>Tiêu đề</label>
    	<input autofocus value="<?php echo $txt_tieude;?>" name="txt_tieude"  style="width:500px;"  type="text" placeholder="Enter title here"/><br />
    </p>
    
    <p>
        <label>Hình ảnh</label>
        <input type="file" name="txt_anh" id="txt_anh" /> 
    </p>
 	
    <p>
        <label>Mô tả</label>
        <textarea name="txt_mota" class="text-input textarea ckeditor" rows="10" cols="10" ><?php echo $txt_mota;?></textarea> 
    </p>
    
    <p>
        <label>Nội dung</label>
        <textarea name="txt_noidung" class="text-input textarea ckeditor" rows="10" cols="10" ><?php echo $txt_noidung;?></textarea> 
    </p>
    

    <p>
    	<input class="button" type="submit" value="Cập nhập" name="them" style="width:100px"/>
    </p>
     </fieldset>
                
                <div class="clear"></div><!-- End .clear -->
                
</form>
    
    <?php 
	}
	else{
				//Define some variables  
		$dir = "uploads/tintuc/"; //Bạn nên thay đổi đường dẫn cho phù hợp 
		//Kiều file, Gif, jpeg, zip ::bạn có thể sửa đổi nếu thích 
		$types = array("image/gif","image/GIF","image/JPG","image/PNG","image/png","image/jpg","image/JPEG","image/jpeg","application/x-zip-compressed","application/msword","application/vnd.ms-excel");     
		//Check to determine if the submit button has been pressed  
		if(isset($_POST["them"])){ 
		//Shorten Variables  
			 $tmp_name = $_FILES["txt_anh"]["tmp_name"];  
			 $new_name = $_FILES["txt_anh"]["name"]; 
		//Check MIME Type  
			if (in_array($_FILES["txt_anh"]["type"], $types)){                     
				 //Move file from tmp dir to new location  
				move_uploaded_file($tmp_name,'../'.$dir . $new_name);    
		  $txt_anh=$new_name;        
				echo "<script>alert('File {$_FILES["txt_anh"]["name"]} đã gửi xong!');</script>"; 
			}else{                 
			//Print Error Message  
			 echo "<script>alert('{$_FILES["txt_anh"]["name"]} upload file thất bại !');</script>";       
			//Debug  
		   $name =  $_FILES["txt_anh"]["name"];  
		   $type =    $_FILES["txt_anh"]["type"];  
		   $size =    $_FILES["txt_anh"]["size"];  
		   $tmp =     $_FILES["txt_anh"]["name"];      
		   echo "Name: $name<br/ >Type: $type<br />Size: $size<br />Tmp: $tmp";               
			}       
			}       
		else{       
			echo 'Không có file upload';   
		}
		if($txt_anh=='')
		{
			$sql="	UPDATE 	tbl_tintuc 
								SET 	tieude='".$txt_tieude."',
						
										mota='".$txt_mota."',
										noidung='".$txt_noidung."'

								WHERE id='".$id."'";
				$result=mysql_query($sql);
				header('refresh:1; index.php?page=new');
		}else
			{	
				$sql="	UPDATE 	tbl_tintuc 
								SET 	tieude='".$txt_tieude."',
										anh='".$txt_anh."',
										mota='".$txt_mota."',
										noidung='".$txt_noidung."'
								WHERE id='".$id."'";
				$result=mysql_query($sql);
				header('refresh:1; index.php?page=new');
			}
		}
?>
</div><!--qt-composer-->
</div>
</div> <!-- End #tab1 -->

             

    </div> <!-- End .content-box-content -->
    
</div> <!-- End .content-box -->
